﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Z2102WinForms.LX
{
    public partial class Form4 : Form
    {
        public Form4()
        {
            InitializeComponent();

            label1.Text = "上机练习4 字母判断（要求分别用Console和WinForms实现）。";
            label2.AutoEllipsis = true;
            button1.Click += Button1_Click;

            panel1.Visible = false;
            buttonConsole.Click += delegate
            {
                Program.ExecConsoleApp("Z2102Console.LX.Class4");
            };
            buttonWinForms.Click += delegate
            {
                panel1.Visible = true;
            };
        }

        private void Button1_Click(object? sender, EventArgs e)
        {
            string str = textBox1.Text;
            if (str.Length != 5)
            {
                label2.Text = "字符串长度不符合要求（字母个数不是5个），请重新输入！";
                return;
            }
            bool isValid = true;
            for (int i = 0; i < 5; i++)
            {
                char c = str[i];
                if (c < 'A' || c > 'Z')
                {
                    label2.Text = $"第{i + 1}个字符“{c}”不是大写字母，请重新输入。";
                    isValid = false;
                    break;
                }
            }
            if (!isValid)
            {
                return;
            }
            label2.Text = "输入的字符满足要求。";
        }
    }
}
